package com.flymobi.mshop.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.flymobi.mshop.R;
import com.flymobi.mshop.po.Order;
import com.flymobi.mshop.util.Constants;

public class FaPiao extends CommonActivity implements OnItemSelectedListener{
	private TextView tvtype;
	private RadioGroup rgrdo;
	private RadioButton rbgeren;
	private RadioButton rbdanwei;
	private EditText danweiname;
	private Spinner prodleixing;
	private Button btnok;
	private String rdo;
	private TextView spprod;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fapiaoinfo);
		Init();
		btnok.setOnClickListener(new okClick());
		rgrdo.setOnCheckedChangeListener(new rdoChange());
		prodleixing = new Spinner(FaPiao.this);
		ArrayAdapter<String> valueAdp = new ArrayAdapter<String>(
				FaPiao.this,
				android.R.layout.simple_spinner_item, Constants.DD.SHUZU.leixing);
		valueAdp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
		prodleixing.setAdapter(valueAdp); 
		prodleixing.setOnItemSelectedListener(this);
		}
	
	class rdoChange implements OnCheckedChangeListener{
		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			// TODO Auto-generated method stub
			if(checkedId==R.id.rbgeren){
				rdo = "个人";
			}else{
				rdo = "单位";
			}
		}
	}
	
	class okClick implements OnClickListener{
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Order.setType(tvtype.getText().toString());
			Order.setDanwei(rdo);
			Order.setDanweiname(danweiname.getText().toString());
			Order.setLeixing(spprod.getText().toString()==null?"":spprod.getText().toString());
			Intent intent = new Intent();
			intent.setClass(FaPiao.this, FillOrder.class);
			FaPiao.this.startActivity(intent);
		}
	}
	
	private void Init(){
		tvtype = (TextView) findViewById(R.id.tvtype);
		rgrdo = (RadioGroup) findViewById(R.id.rgrdo);
		rbgeren = (RadioButton) findViewById(R.id.rbgeren);
		rbdanwei = (RadioButton) findViewById(R.id.rbdanwei);
		danweiname = (EditText) findViewById(R.id.danweiname);
		prodleixing = (Spinner) findViewById(R.id.prodleixing);
		btnok = (Button) findViewById(R.id.btnok);
	}

	@Override
	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		// TODO Auto-generated method stub
		spprod = new TextView(FaPiao.this);
		spprod.setText(Constants.DD.SHUZU.leixing[arg2]);
	}

	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
		
	}
}
